<div class="row">
<div class="span12">      		
	   		
	<div class="widget ">
		<div class="widget-header">
			<i class="icon-th-list"></i>
 			<h3>任务执行日志</h3>
		</div> <!-- /widget-header -->

		<div class="widget-content">
		
		<div class="alert hide" role="alert"></div>
		
		<p>
		<h3>{{.task.TaskName}} （#{{.task.Id}}）</h3>

		<pre>{{.task.Command}}</pre>
		</p>
		<hr />
		
		<div class="btn-toolbar">
		
			<div class="btn-group btn-batch">
				<a class="btn btn-large" href="#"><i class="icon-edit icon-white"></i> 批量操作</a>
				<a class="btn btn-large dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
				<ul class="dropdown-menu">
				<li><a href="javascript:;" onclick="javascript:batch('delete');"><i class="icon-trash"></i> 删除</a></li>
				</ul>
			</div>
			
			<div class="btn-group">
				<a href="{{urlfor "TaskController.List"}}" class="btn btn-large"><span class="icon-chevron-left"></span> 返 回</a>
			</div>
			
		</div>

		<form id="form-list" method="post" action="">
		<table class="table table-striped table-bordered table-hover">
			<thead>
			<tr>
				<th width="20"><input type="checkbox" name="chkall" value="1"></td>
				<th width="40">ID</th>
				<th>开始时间</th>
				<th>执行时间</th>
				<th>输出</th>
				<th class="span2">状态</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			{{range $k, $v := .list}}
				<tr>
					<td><input type="checkbox" name="ids" value="{{$v.id}}" /></td>
					<td class="center">{{$v.id}}</td>
					<td>{{$v.start_time}}</td>
					<td>{{$v.process_time}} 秒</td>
					<td>{{$v.ouput_size}}</td>
					<td>
					{{if eq $v.status 0}}
					<span class="icon-ok-sign" style="color:green"> 正常</span>
					{{else if eq $v.status -1}}
					<span class=" icon-remove-sign" style="color:#ff7f74"> 出错</span>
					{{else if eq $v.status -2}}
					<span class=" icon-remove-sign" style="color:#ff7f74"> 超时</span>
					{{end}}
					</td>
					<td>
						<a class="btn btn-info" href="{{urlfor "TaskController.ViewLog"}}?id={{$v.id}}">
							<i class="icon-comment"></i> 详情
                       </a>					
					</td>
				</tr>
			{{end}}
			</tbody>
			<tfoot>
				<tr><td colspan="100">{{str2html .pageBar}}</td></tr>
			</tfoot>
		</table>
		</form>
		
		</div>
	</div>
</div>
</div> <!-- /row -->

<script>
$(function() {
	$("input[name='chkall']").click(function () {
		$("input[name='ids']").attr("checked", $(this).attr("checked") == "checked");
	});
});

function batch(action) {
	$(".alert").hide();
	if ($("input[name='ids']:checked").size() < 1) {
		$(".alert").text("请选择要操作的任务");
		$(".alert").show();
	} else {
		var url = "{{urlfor "TaskController.LogBatch"}}";
		$.post(url + "?action=" + action, $("#form-list").serialize(), function(out) {
			if (out.status != 0) {
				$(".alert").text(out.msg);
				$(".alert").show();
			} else {
				window.location.reload();
			}
		}, "json");
	}
	return false;
}
</script>